package com.sxfq.loansupermarket.backsystem.modular.refunds.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.common.persistence.model.Dept;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.util.StringUtil;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import com.sxfq.loansupermarket.backsystem.modular.refunds.dao.PerformanceDao;
import com.sxfq.loansupermarket.backsystem.modular.refunds.entity.PerformanceInfo;
import com.sxfq.loansupermarket.backsystem.modular.refunds.entity.SearchPerformanceInfo;
import com.sxfq.loansupermarket.backsystem.modular.refunds.service.IPerformanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class PerformanceServiceImpl implements IPerformanceService {
    @Autowired
    PerformanceDao dao;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private SqlMapper sqlMapper;

    @Override
    public List<PerformanceInfo> selectPageListQueryPages(Page<PerformanceInfo> page, SearchPerformanceInfo info) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(info.getStartRechargeTime())) {
            params.put("startRechargeTime", info.getStartRechargeTime());
        }
        if (StringUtil.isNotEmpty(info.getEndRechargeTime())) {
            params.put("endRechargeTime", info.getEndRechargeTime());
        }
        if (StringUtil.isNotEmpty(info.getOutpatientName())) {
            params.put("outpatientName", info.getOutpatientName());
        }
        if (StringUtil.isNotEmpty(info.getCustomerStatus())) {
            String customerStatus = "";
            String customerStatus2[] = info.getCustomerStatus().split(",");
            if (customerStatus2.length == 1) {
                customerStatus = customerStatus2[0];
            } else {
                for (int i = 0; i < customerStatus2.length; i++) {
                    if (i == (customerStatus2.length - 1)) {
                        customerStatus += "'" + customerStatus2[i];
                    } else if (i == 0) {
                        customerStatus += customerStatus2[i] + "'" + ",";
                    } else {
                        customerStatus += "'" + customerStatus2[i] + "'" + ",";
                    }
                }
            }
            params.put("customerStatus", " ('" + customerStatus + "')");
        }
        if (StringUtil.isNotEmpty(info.getIsDoName())) {
            if ("9".equals(info.getIsDoName())) {
                params.put("isDo", " '" + info.getIsDoName() + "' ");
                params.put("isEarnes", " and t1.isEarnes=2");
            }else if ("10".equals(info.getIsDoName())) {
                params.put("isDo", " '" + info.getIsDoName() + "' ");
                params.put("isEarnes", " and t1.isEarnes=10");
            } else {
                params.put("isDo", " '" + info.getIsDoName() + "'");
                params.put("isDos", " '9'");
            }
        }else{
            params.put("isEarnes", " and t1.isEarnes in (10,2) ");
        }
        if (StringUtil.isNotEmpty(info.getReach())) {
            params.put("reach", info.getReach());
        }
        if (StringUtil.isNotEmpty(info.getOneChannel())) {
            if (info.getOneChannel().indexOf("请选择") == -1) {
                String oneChannel = "";
                String oneChannel2[] = info.getOneChannel().split(",");
                if (oneChannel2.length == 1) {
                    oneChannel = oneChannel2[0];
                } else {
                    for (int i = 0; i < oneChannel2.length; i++) {
                        if (i == (oneChannel2.length - 1)) {
                            oneChannel += "'" + oneChannel2[i];
                        } else if (i == 0) {
                            oneChannel += oneChannel2[i] + "'" + ",";
                        } else {
                            oneChannel += "'" + oneChannel2[i] + "'" + ",";
                        }
                    }
                }
                params.put("oneChannel", " ('" + oneChannel + "')");
            }
        }
        if (StringUtil.isNotEmpty(info.getTwoChannel())) {
            if (info.getTwoChannel().indexOf("请选择") == -1) {
                String twoChannel = "";
                String twoChannel2[] = info.getTwoChannel().split(",");
                if (twoChannel2.length == 1) {
                    twoChannel = twoChannel2[0];
                } else {
                    for (int i = 0; i < twoChannel2.length; i++) {
                        if (i == (twoChannel2.length - 1)) {
                            twoChannel += "'" + twoChannel2[i];
                        } else if (i == 0) {
                            twoChannel += twoChannel2[i] + "'" + ",";
                        } else {
                            twoChannel += "'" + twoChannel2[i] + "'" + ",";
                        }
                    }
                }
                params.put("twoChannel", " ('" + twoChannel + "')");
            }
        }
        if (StringUtil.isNotEmpty(info.getThrChannel())) {
            if (info.getThrChannel().indexOf("请选择") == -1) {
                String thrChannel = "";
                String thrChannel2[] = info.getThrChannel().split(",");
                if (thrChannel2.length == 1) {
                    thrChannel = thrChannel2[0];
                } else {
                    for (int i = 0; i < thrChannel2.length; i++) {
                        if (i == (thrChannel2.length - 1)) {
                            thrChannel += "'" + thrChannel2[i];
                        } else if (i == 0) {
                            thrChannel += thrChannel2[i] + "'" + ",";
                        } else {
                            thrChannel += "'" + thrChannel2[i] + "'" + ",";
                        }
                    }
                }
                params.put("thrChannel", " ('" + thrChannel + "')");
            }
        }

        if (StringUtil.isNotEmpty(info.getOneMedium())) {
            if (info.getOneMedium().indexOf("请选择") == -1) {
                String oneMedium = "";
                String oneMedium2[] = info.getOneMedium().split(",");
                if (oneMedium2.length == 1) {
                    oneMedium = oneMedium2[0];
                } else {
                    for (int i = 0; i < oneMedium2.length; i++) {
                        if (i == (oneMedium2.length - 1)) {
                            oneMedium += "'" + oneMedium2[i];
                        } else if (i == 0) {
                            oneMedium += oneMedium2[i] + "'" + ",";
                        } else {
                            oneMedium += "'" + oneMedium2[i] + "'" + ",";
                        }
                    }
                }
                params.put("oneMedium", " ('" + oneMedium + "')");
            }
        }
        if (StringUtil.isNotEmpty(info.getTwoMedium())) {
            if (info.getTwoMedium().indexOf("请选择") == -1) {
                String twoMedium = "";
                String twoMedium2[] = info.getTwoMedium().split(",");
                if (twoMedium2.length == 1) {
                    twoMedium = twoMedium2[0];
                } else {
                    for (int i = 0; i < twoMedium2.length; i++) {
                        if (i == (twoMedium2.length - 1)) {
                            twoMedium += "'" + twoMedium2[i];
                        } else if (i == 0) {
                            twoMedium += twoMedium2[i] + "'" + ",";
                        } else {
                            twoMedium += "'" + twoMedium2[i] + "'" + ",";
                        }
                    }
                }
                params.put("twoMedium", " ('" + twoMedium + "')");
            }
        }
        if (StringUtil.isNotEmpty(info.getThrMedium())) {
            if (info.getThrMedium().indexOf("请选择") == -1) {
                String thrMedium = "";
                String thrMedium2[] = info.getThrMedium().split(",");
                if (thrMedium2.length == 1) {
                    thrMedium = thrMedium2[0];
                } else {
                    for (int i = 0; i < thrMedium2.length; i++) {
                        if (i == (thrMedium2.length - 1)) {
                            thrMedium += "'" + thrMedium2[i];
                        } else if (i == 0) {
                            thrMedium += thrMedium2[i] + "'" + ",";
                        } else {
                            thrMedium += "'" + thrMedium2[i] + "'" + ",";
                        }
                    }
                }
                params.put("thrMedium", " ('" + thrMedium + "')");
            }
        }
        if (StringUtil.isNotEmpty(info.getTreatmentUnit())) {
            String treatmentUnit = "";
            String treatmentUnit2[] = info.getTreatmentUnit().split(",");
            if (treatmentUnit2.length == 1) {
                treatmentUnit = treatmentUnit2[0];
            } else {
                for (int i = 0; i < treatmentUnit2.length; i++) {
                    if (i == (treatmentUnit2.length - 1)) {
                        treatmentUnit += "'" + treatmentUnit2[i];
                    } else if (i == 0) {
                        treatmentUnit += treatmentUnit2[i] + "'" + ",";
                    } else {
                        treatmentUnit += "'" + treatmentUnit2[i] + "'" + ",";
                    }
                }
            }
            params.put("treatmentUnit", " ('" + treatmentUnit + "')");
        }
        if (StringUtil.isNotEmpty(info.getScarchiving())) {
            String scarchiving = "";
            String scarchiving2[] = info.getScarchiving().split(",");
            if (scarchiving2.length == 1) {
                scarchiving = scarchiving2[0];
            } else {
                for (int i = 0; i < scarchiving2.length; i++) {
                    if (i == (scarchiving2.length - 1)) {
                        scarchiving += "'" + scarchiving2[i];
                    } else if (i == 0) {
                        scarchiving += scarchiving2[i] + "'" + ",";
                    } else {
                        scarchiving += "'" + scarchiving2[i] + "'" + ",";
                    }
                }
            }
            params.put("scarchiving", " ('" + scarchiving + "')");
        }
        if (StringUtil.isNotEmpty(info.getDoctor())) {
            String doctor = "";
            String doctor2[] = info.getDoctor().split(",");
            if (doctor2.length == 1) {
                doctor = doctor2[0];
            } else {
                for (int i = 0; i < doctor2.length; i++) {
                    if (i == (doctor2.length - 1)) {
                        doctor += "'" + doctor2[i];
                    } else if (i == 0) {
                        doctor += doctor2[i] + "'" + ",";
                    } else {
                        doctor += "'" + doctor2[i] + "'" + ",";
                    }
                }
            }
            params.put("doctor", " ('" + doctor + "')");
        }
        if (StringUtil.isNotEmpty(info.getTcName())) {
            String tcName = "";
            String tcName2[] = info.getTcName().split(",");
            if (tcName2.length == 1) {
                tcName = tcName2[0];
            } else {
                for (int i = 0; i < tcName2.length; i++) {
                    if (i == (tcName2.length - 1)) {
                        tcName += "'" + tcName2[i];
                    } else if (i == 0) {
                        tcName += tcName2[i] + "'" + ",";
                    } else {
                        tcName += "'" + tcName2[i] + "'" + ",";
                    }
                }
            }
            params.put("tcName", " ('" + tcName + "')");
        }
        String getTableHeadsql = "select abbreviation from dept t where t.simplename='" + info.getOutpatientName() + "' limit 1";
        Dept dept = sqlMapper.selectOne(getTableHeadsql, Dept.class);
        String tableHead = dept.getAbbreviation();
        String tableName1 = tableHead + "deal_info";
        String tableName2 = tableHead + "recharge_info";
        params.put("tableName", tableHead+"customer_info");
        params.put("tableName1", tableName1);
        params.put("tableName2", tableName2);
        params.put("startIndex", info.getStartIndex());
        params.put("limitIndex", info.getLimitIndex());
        return dao.getQueryPageAchievementList(page, params);
    }

    public int getQueryPagesCount(Page<PerformanceInfo> page, SearchPerformanceInfo info) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(info.getStartRechargeTime())) {
            params.put("startRechargeTime", info.getStartRechargeTime());
        }
        if (StringUtil.isNotEmpty(info.getEndRechargeTime())) {
            params.put("endRechargeTime", info.getEndRechargeTime());
        }
        if (StringUtil.isNotEmpty(info.getOutpatientName())) {
            params.put("outpatientName", info.getOutpatientName());
        }
        if (StringUtil.isNotEmpty(info.getCustomerStatus())) {
            String customerStatus = "";
            String customerStatus2[] = info.getCustomerStatus().split(",");
            if (customerStatus2.length == 1) {
                customerStatus = customerStatus2[0];
            } else {
                for (int i = 0; i < customerStatus2.length; i++) {
                    if (i == (customerStatus2.length - 1)) {
                        customerStatus += "'" + customerStatus2[i];
                    } else if (i == 0) {
                        customerStatus += customerStatus2[i] + "'" + ",";
                    } else {
                        customerStatus += "'" + customerStatus2[i] + "'" + ",";
                    }
                }
            }
            params.put("customerStatus", " ('" + customerStatus + "')");
        }
        if (StringUtil.isNotEmpty(info.getIsDoName())) {
            if ("9".equals(info.getIsDoName())) {
                params.put("isDo", " '" + info.getIsDoName() + "' ");
                params.put("isEarnes", " and t1.isEarnes=2");
            }else if ("10".equals(info.getIsDoName())) {
                params.put("isDo", " '" + info.getIsDoName() + "' ");
                params.put("isEarnes", " and t1.isEarnes=10");
            } else {
                params.put("isDo", " '" + info.getIsDoName() + "'");
                params.put("isDos", " '9'");
            }
        }else{
            params.put("isEarnes", " and t1.isEarnes in (10,2) ");
        }
        if (StringUtil.isNotEmpty(info.getReach())) {
            params.put("reach", info.getReach());
        }
        if (StringUtil.isNotEmpty(info.getOneChannel())) {
            if (info.getOneChannel().indexOf("请选择") == -1) {
                String oneChannel = "";
                String oneChannel2[] = info.getOneChannel().split(",");
                if (oneChannel2.length == 1) {
                    oneChannel = oneChannel2[0];
                } else {
                    for (int i = 0; i < oneChannel2.length; i++) {
                        if (i == (oneChannel2.length - 1)) {
                            oneChannel += "'" + oneChannel2[i];
                        } else if (i == 0) {
                            oneChannel += oneChannel2[i] + "'" + ",";
                        } else {
                            oneChannel += "'" + oneChannel2[i] + "'" + ",";
                        }
                    }
                }
                params.put("oneChannel", " ('" + oneChannel + "')");
            }
        }
        if (StringUtil.isNotEmpty(info.getTwoChannel())) {
            if (info.getTwoChannel().indexOf("请选择") == -1) {
                String twoChannel = "";
                String twoChannel2[] = info.getTwoChannel().split(",");
                if (twoChannel2.length == 1) {
                    twoChannel = twoChannel2[0];
                } else {
                    for (int i = 0; i < twoChannel2.length; i++) {
                        if (i == (twoChannel2.length - 1)) {
                            twoChannel += "'" + twoChannel2[i];
                        } else if (i == 0) {
                            twoChannel += twoChannel2[i] + "'" + ",";
                        } else {
                            twoChannel += "'" + twoChannel2[i] + "'" + ",";
                        }
                    }
                }
                params.put("twoChannel", " ('" + twoChannel + "')");
            }
        }
        if (StringUtil.isNotEmpty(info.getThrChannel())) {
            if (info.getThrChannel().indexOf("请选择") == -1) {
                String thrChannel = "";
                String thrChannel2[] = info.getThrChannel().split(",");
                if (thrChannel2.length == 1) {
                    thrChannel = thrChannel2[0];
                } else {
                    for (int i = 0; i < thrChannel2.length; i++) {
                        if (i == (thrChannel2.length - 1)) {
                            thrChannel += "'" + thrChannel2[i];
                        } else if (i == 0) {
                            thrChannel += thrChannel2[i] + "'" + ",";
                        } else {
                            thrChannel += "'" + thrChannel2[i] + "'" + ",";
                        }
                    }
                }
                params.put("thrChannel", " ('" + thrChannel + "')");
            }
        }

        if (StringUtil.isNotEmpty(info.getOneMedium())) {
            if (info.getOneMedium().indexOf("请选择") == -1) {
                String oneMedium = "";
                String oneMedium2[] = info.getOneMedium().split(",");
                if (oneMedium2.length == 1) {
                    oneMedium = oneMedium2[0];
                } else {
                    for (int i = 0; i < oneMedium2.length; i++) {
                        if (i == (oneMedium2.length - 1)) {
                            oneMedium += "'" + oneMedium2[i];
                        } else if (i == 0) {
                            oneMedium += oneMedium2[i] + "'" + ",";
                        } else {
                            oneMedium += "'" + oneMedium2[i] + "'" + ",";
                        }
                    }
                }
                params.put("oneMedium", " ('" + oneMedium + "')");
            }
        }
        if (StringUtil.isNotEmpty(info.getTwoMedium())) {
            if (info.getTwoMedium().indexOf("请选择") == -1) {
                String twoMedium = "";
                String twoMedium2[] = info.getTwoMedium().split(",");
                if (twoMedium2.length == 1) {
                    twoMedium = twoMedium2[0];
                } else {
                    for (int i = 0; i < twoMedium2.length; i++) {
                        if (i == (twoMedium2.length - 1)) {
                            twoMedium += "'" + twoMedium2[i];
                        } else if (i == 0) {
                            twoMedium += twoMedium2[i] + "'" + ",";
                        } else {
                            twoMedium += "'" + twoMedium2[i] + "'" + ",";
                        }
                    }
                }
                params.put("twoMedium", " ('" + twoMedium + "')");
            }
        }
        if (StringUtil.isNotEmpty(info.getThrMedium())) {
            if (info.getThrMedium().indexOf("请选择") == -1) {
                String thrMedium = "";
                String thrMedium2[] = info.getThrMedium().split(",");
                if (thrMedium2.length == 1) {
                    thrMedium = thrMedium2[0];
                } else {
                    for (int i = 0; i < thrMedium2.length; i++) {
                        if (i == (thrMedium2.length - 1)) {
                            thrMedium += "'" + thrMedium2[i];
                        } else if (i == 0) {
                            thrMedium += thrMedium2[i] + "'" + ",";
                        } else {
                            thrMedium += "'" + thrMedium2[i] + "'" + ",";
                        }
                    }
                }
                params.put("thrMedium", " ('" + thrMedium + "')");
            }
        }
        if (StringUtil.isNotEmpty(info.getTreatmentUnit())) {
            String treatmentUnit = "";
            String treatmentUnit2[] = info.getTreatmentUnit().split(",");
            if (treatmentUnit2.length == 1) {
                treatmentUnit = treatmentUnit2[0];
            } else {
                for (int i = 0; i < treatmentUnit2.length; i++) {
                    if (i == (treatmentUnit2.length - 1)) {
                        treatmentUnit += "'" + treatmentUnit2[i];
                    } else if (i == 0) {
                        treatmentUnit += treatmentUnit2[i] + "'" + ",";
                    } else {
                        treatmentUnit += "'" + treatmentUnit2[i] + "'" + ",";
                    }
                }
            }
            params.put("treatmentUnit", " ('" + treatmentUnit + "')");
        }
        if (StringUtil.isNotEmpty(info.getScarchiving())) {
            String scarchiving = "";
            String scarchiving2[] = info.getScarchiving().split(",");
            if (scarchiving2.length == 1) {
                scarchiving = scarchiving2[0];
            } else {
                for (int i = 0; i < scarchiving2.length; i++) {
                    if (i == (scarchiving2.length - 1)) {
                        scarchiving += "'" + scarchiving2[i];
                    } else if (i == 0) {
                        scarchiving += scarchiving2[i] + "'" + ",";
                    } else {
                        scarchiving += "'" + scarchiving2[i] + "'" + ",";
                    }
                }
            }
            params.put("scarchiving", " ('" + scarchiving + "')");
        }
        if (StringUtil.isNotEmpty(info.getDoctor())) {
            String doctor = "";
            String doctor2[] = info.getDoctor().split(",");
            if (doctor2.length == 1) {
                doctor = doctor2[0];
            } else {
                for (int i = 0; i < doctor2.length; i++) {
                    if (i == (doctor2.length - 1)) {
                        doctor += "'" + doctor2[i];
                    } else if (i == 0) {
                        doctor += doctor2[i] + "'" + ",";
                    } else {
                        doctor += "'" + doctor2[i] + "'" + ",";
                    }
                }
            }
            params.put("doctor", " ('" + doctor + "')");
        }
        if (StringUtil.isNotEmpty(info.getTcName())) {
            String tcName = "";
            String tcName2[] = info.getTcName().split(",");
            if (tcName2.length == 1) {
                tcName = tcName2[0];
            } else {
                for (int i = 0; i < tcName2.length; i++) {
                    if (i == (tcName2.length - 1)) {
                        tcName += "'" + tcName2[i];
                    } else if (i == 0) {
                        tcName += tcName2[i] + "'" + ",";
                    } else {
                        tcName += "'" + tcName2[i] + "'" + ",";
                    }
                }
            }
            params.put("tcName", " ('" + tcName + "')");
        }
        String getTableHeadsql = "select abbreviation from dept t where t.simplename='" + info.getOutpatientName() + "' limit 1";
        Dept dept = sqlMapper.selectOne(getTableHeadsql, Dept.class);
        String tableHead = dept.getAbbreviation();
        String tableName1 = tableHead + "deal_info";
        String tableName2 = tableHead + "recharge_info";
        params.put("tableName", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0));
        params.put("tableName1", tableName1);
        params.put("tableName2", tableName2);
        return dao.getQueryPagesCount(page, params);
    }

    @Override
    public List<PerformanceInfo> getperformanceTableExport(SearchPerformanceInfo info) {
        Map<String, Object> params = new HashMap<String, Object>();
        if (StringUtil.isNotEmpty(info.getStartRechargeTime())) {
            params.put("startRechargeTime", info.getStartRechargeTime());
        }
        if (StringUtil.isNotEmpty(info.getEndRechargeTime())) {
            params.put("endRechargeTime", info.getEndRechargeTime());
        }
        if (StringUtil.isNotEmpty(info.getOutpatientName())) {
            params.put("outpatientName", info.getOutpatientName());
        }
        if (StringUtil.isNotEmpty(info.getCustomerStatus())) {
            String customerStatus = "";
            String customerStatus2[] = info.getCustomerStatus().split(",");
            if (customerStatus2.length == 1) {
                customerStatus = customerStatus2[0];
            } else {
                for (int i = 0; i < customerStatus2.length; i++) {
                    if (i == (customerStatus2.length - 1)) {
                        customerStatus += "'" + customerStatus2[i];
                    } else if (i == 0) {
                        customerStatus += customerStatus2[i] + "'" + ",";
                    } else {
                        customerStatus += "'" + customerStatus2[i] + "'" + ",";
                    }
                }
            }
            params.put("customerStatus", " ('" + customerStatus + "')");
        }
        if (StringUtil.isNotEmpty(info.getIsDoName())) {
            if ("9".equals(info.getIsDoName())) {
                params.put("isDo", " '" + info.getIsDoName() + "' ");
                params.put("isEarnes", " and t1.isEarnes=2");
            }else if ("10".equals(info.getIsDoName())) {
                params.put("isDo", " '" + info.getIsDoName() + "' ");
                params.put("isEarnes", " and t1.isEarnes=10");
            } else {
                params.put("isDo", " '" + info.getIsDoName() + "'");
                params.put("isDos", " '9'");
            }
        }else{
            params.put("isEarnes", " and t1.isEarnes in (10,2) ");
        }
        if (StringUtil.isNotEmpty(info.getReach())) {
            params.put("reach", info.getReach());
        }
        if (StringUtil.isNotEmpty(info.getOneChannel())) {
            if (info.getOneChannel().indexOf("请选择") == -1) {
                String oneChannel = "";
                String oneChannel2[] = info.getOneChannel().split(",");
                if (oneChannel2.length == 1) {
                    oneChannel = oneChannel2[0];
                } else {
                    for (int i = 0; i < oneChannel2.length; i++) {
                        if (i == (oneChannel2.length - 1)) {
                            oneChannel += "'" + oneChannel2[i];
                        } else if (i == 0) {
                            oneChannel += oneChannel2[i] + "'" + ",";
                        } else {
                            oneChannel += "'" + oneChannel2[i] + "'" + ",";
                        }
                    }
                }
                params.put("oneChannel", " ('" + oneChannel + "')");
            }
        }
        if (StringUtil.isNotEmpty(info.getTwoChannel())) {
            if (info.getTwoChannel().indexOf("请选择") == -1) {
                String twoChannel = "";
                String twoChannel2[] = info.getTwoChannel().split(",");
                if (twoChannel2.length == 1) {
                    twoChannel = twoChannel2[0];
                } else {
                    for (int i = 0; i < twoChannel2.length; i++) {
                        if (i == (twoChannel2.length - 1)) {
                            twoChannel += "'" + twoChannel2[i];
                        } else if (i == 0) {
                            twoChannel += twoChannel2[i] + "'" + ",";
                        } else {
                            twoChannel += "'" + twoChannel2[i] + "'" + ",";
                        }
                    }
                }
                params.put("twoChannel", " ('" + twoChannel + "')");
            }
        }
        if (StringUtil.isNotEmpty(info.getThrChannel())) {
            if (info.getThrChannel().indexOf("请选择") == -1) {
                String thrChannel = "";
                String thrChannel2[] = info.getThrChannel().split(",");
                if (thrChannel2.length == 1) {
                    thrChannel = thrChannel2[0];
                } else {
                    for (int i = 0; i < thrChannel2.length; i++) {
                        if (i == (thrChannel2.length - 1)) {
                            thrChannel += "'" + thrChannel2[i];
                        } else if (i == 0) {
                            thrChannel += thrChannel2[i] + "'" + ",";
                        } else {
                            thrChannel += "'" + thrChannel2[i] + "'" + ",";
                        }
                    }
                }
                params.put("thrChannel", " ('" + thrChannel + "')");
            }
        }

        if (StringUtil.isNotEmpty(info.getOneMedium())) {
            if (info.getOneMedium().indexOf("请选择") == -1) {
                String oneMedium = "";
                String oneMedium2[] = info.getOneMedium().split(",");
                if (oneMedium2.length == 1) {
                    oneMedium = oneMedium2[0];
                } else {
                    for (int i = 0; i < oneMedium2.length; i++) {
                        if (i == (oneMedium2.length - 1)) {
                            oneMedium += "'" + oneMedium2[i];
                        } else if (i == 0) {
                            oneMedium += oneMedium2[i] + "'" + ",";
                        } else {
                            oneMedium += "'" + oneMedium2[i] + "'" + ",";
                        }
                    }
                }
                params.put("oneMedium", " ('" + oneMedium + "')");
            }
        }
        if (StringUtil.isNotEmpty(info.getTwoMedium())) {
            if (info.getTwoMedium().indexOf("请选择") == -1) {
                String twoMedium = "";
                String twoMedium2[] = info.getTwoMedium().split(",");
                if (twoMedium2.length == 1) {
                    twoMedium = twoMedium2[0];
                } else {
                    for (int i = 0; i < twoMedium2.length; i++) {
                        if (i == (twoMedium2.length - 1)) {
                            twoMedium += "'" + twoMedium2[i];
                        } else if (i == 0) {
                            twoMedium += twoMedium2[i] + "'" + ",";
                        } else {
                            twoMedium += "'" + twoMedium2[i] + "'" + ",";
                        }
                    }
                }
                params.put("twoMedium", " ('" + twoMedium + "')");
            }
        }
        if (StringUtil.isNotEmpty(info.getThrMedium())) {
            if (info.getThrMedium().indexOf("请选择") == -1) {
                String thrMedium = "";
                String thrMedium2[] = info.getThrMedium().split(",");
                if (thrMedium2.length == 1) {
                    thrMedium = thrMedium2[0];
                } else {
                    for (int i = 0; i < thrMedium2.length; i++) {
                        if (i == (thrMedium2.length - 1)) {
                            thrMedium += "'" + thrMedium2[i];
                        } else if (i == 0) {
                            thrMedium += thrMedium2[i] + "'" + ",";
                        } else {
                            thrMedium += "'" + thrMedium2[i] + "'" + ",";
                        }
                    }
                }
                params.put("thrMedium", " ('" + thrMedium + "')");
            }
        }
        if (StringUtil.isNotEmpty(info.getTreatmentUnit())) {
            String treatmentUnit = "";
            String treatmentUnit2[] = info.getTreatmentUnit().split(",");
            if (treatmentUnit2.length == 1) {
                treatmentUnit = treatmentUnit2[0];
            } else {
                for (int i = 0; i < treatmentUnit2.length; i++) {
                    if (i == (treatmentUnit2.length - 1)) {
                        treatmentUnit += "'" + treatmentUnit2[i];
                    } else if (i == 0) {
                        treatmentUnit += treatmentUnit2[i] + "'" + ",";
                    } else {
                        treatmentUnit += "'" + treatmentUnit2[i] + "'" + ",";
                    }
                }
            }
            params.put("treatmentUnit", " ('" + treatmentUnit + "')");
        }
        if (StringUtil.isNotEmpty(info.getScarchiving())) {
            String scarchiving = "";
            String scarchiving2[] = info.getScarchiving().split(",");
            if (scarchiving2.length == 1) {
                scarchiving = scarchiving2[0];
            } else {
                for (int i = 0; i < scarchiving2.length; i++) {
                    if (i == (scarchiving2.length - 1)) {
                        scarchiving += "'" + scarchiving2[i];
                    } else if (i == 0) {
                        scarchiving += scarchiving2[i] + "'" + ",";
                    } else {
                        scarchiving += "'" + scarchiving2[i] + "'" + ",";
                    }
                }
            }
            params.put("scarchiving", " ('" + scarchiving + "')");
        }
        if (StringUtil.isNotEmpty(info.getDoctor())) {
            String doctor = "";
            String doctor2[] = info.getDoctor().split(",");
            if (doctor2.length == 1) {
                doctor = doctor2[0];
            } else {
                for (int i = 0; i < doctor2.length; i++) {
                    if (i == (doctor2.length - 1)) {
                        doctor += "'" + doctor2[i];
                    } else if (i == 0) {
                        doctor += doctor2[i] + "'" + ",";
                    } else {
                        doctor += "'" + doctor2[i] + "'" + ",";
                    }
                }
            }
            params.put("doctor", " ('" + doctor + "')");
        }
        if (StringUtil.isNotEmpty(info.getTcName())) {
            String tcName = "";
            String tcName2[] = info.getTcName().split(",");
            if (tcName2.length == 1) {
                tcName = tcName2[0];
            } else {
                for (int i = 0; i < tcName2.length; i++) {
                    if (i == (tcName2.length - 1)) {
                        tcName += "'" + tcName2[i];
                    } else if (i == 0) {
                        tcName += tcName2[i] + "'" + ",";
                    } else {
                        tcName += "'" + tcName2[i] + "'" + ",";
                    }
                }
            }
            params.put("tcName", " ('" + tcName + "')");
        }
        String getTableHeadsql = "select abbreviation from dept t where t.simplename='" + info.getOutpatientName() + "' limit 1";
        Dept dept = sqlMapper.selectOne(getTableHeadsql, Dept.class);
        String tableHead = dept.getAbbreviation();
        String tableName1 = tableHead + "deal_info";
        String tableName2 = tableHead + "recharge_info";
        params.put("tableName", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"customer_info",0));
        params.put("tableName1", tableName1);
        params.put("tableName2", tableName2);
        params.put("startIndex", info.getStartIndex());
        params.put("limitIndex", info.getLimitIndex());
        return dao.getperformanceTableExport(params);
    }
}